<template>
	<view class="orther_data_box">
		<view class="item left">
			<view class="content">
				<view class="title">
					宿舍余额
				</view>
				<view class="nums">
					{{changeNums(parseFloat(balance),100000)}}元
				</view>
			</view>
			<view class="content">
				<view class="title">
					宿舍账单
				</view>
				<view class="nums">
					{{changeNums((billNums),100000)}}条
				</view>
			</view>
		</view>
		<view class="item right">
			<view class="content">
				<view class="title">
					<view class="title_info text_ellipsis">
						近期加入的成员
					</view>
				</view>
				<view class="joiner_list">
					<scroll-view
						:lower-threshold="0" 
						:upper-threshold="0"
						:scroll-top="scrollTop" 
						@scrolltolower="scrolltolower"
						@scrolltoupper="scrolltoupper"
						:scroll-y="true"
						class="scroll-Y">
					<view class="new_joiner_name" v-for="item in newJoinerData" :key="item.user_id">
						<Avatar
							:fileName="item.user_avatar" 
							size="50rpx"/>
						<view class="name text_ellipsis">
							{{item.nick_name_by_dormitory}}
						</view>
					</view>
					</scroll-view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {onMounted,ref,getCurrentInstance} from 'vue'
	import {
		onLoad,
		onReady,
		onHide,
		onUnload
	} from '@dcloudio/uni-app'
	import {
		dynamicStyleStore
	} from '@/stores/dynamicStyle.js'
	import {
		changeNums
	} from '@/utils/changeData.js'
	
	const dynamicStyle_store = dynamicStyleStore()
	
	const props = defineProps({
		balance:{
			type:String
		},
		billNums:{
			type:Number
		},
		newJoinerData:{
			type:Array
		}
	})
	
	const {
		primary_hot_color,
		primary_shallow_color,
		primary_text_color,
		dormitory_orther_left_shadow_one,
		dormitory_orther_left_shadow_two,
		dormitory_orther_right_shadow_one,
		dormitory_orther_right_shadow_two
	} = dynamicStyle_store.dormitoryStyle
	
	const rightHeight = ref('0rpx')
	const scrollTop = ref(0)
	let timer = ref(null)
	const _symbol=ref('')
	//自动滚动
	const autoScroolFun=()=>{
		scrollTop.value+=Number(_symbol.value+2)
	}
	//滚动到底部
	const scrolltolower=()=>{
		_symbol.value='-'
	}
	//滚动了顶部
	const scrolltoupper=()=>{
		_symbol.value=''
	}
	const getRightDomFun=()=>{
		const currentInstance = getCurrentInstance();
		const query = uni.createSelectorQuery().in(currentInstance);
		query.select('.right').boundingClientRect(data => {
			const {height} = data
			rightHeight.value = (height+(height/3))+'rpx'
			timer.value=setInterval(autoScroolFun,100)
		}).exec();
	}
	// #ifdef H5
	onMounted(()=>{
		getRightDomFun()
	})
	// #endif
	onReady(()=>{
		getRightDomFun()
	})
	onHide(()=>{
		clearInterval(timer.value)
	})
	onUnload(()=>{
		clearInterval(timer.value)
	})
	
</script>

<style lang="less">
	.text_ellipsis{
		white-space:nowrap;
		text-overflow:ellipsis;
		overflow: hidden;
	}
	.orther_data_box{
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100%;
		.item{
			width: 40%;
			height: 90%;
			margin: 10rpx 20rpx;
			border-radius: 20rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: center;
			align-items: center;
			.content{
				width: 100%;
				padding: 20rpx;
				.title{
					width: 100%;
					display: flex;
					justify-content: center;
					font-size: 26rpx;
					color: v-bind(primary_text_color);
				}
				.nums{
					width: 100%;
					display: flex;
					justify-content: center;
					font-size: 40rpx;
				}
			}
		}
		.left{
			color: v-bind(primary_hot_color);
			background: v-bind(primary_shallow_color);
			box-shadow:
				7px 4px 7px v-bind(dormitory_orther_left_shadow_one),
				-7px -7px 12px v-bind(dormitory_orther_left_shadow_two);
		}
		.right{
			background-color: v-bind(primary_hot_color);
			box-shadow:
				7px 4px 7px v-bind(dormitory_orther_right_shadow_one),
				-7px -7px 12px v-bind(dormitory_orther_right_shadow_two);
			.content{
				height: 80%;
				.title{
					color: #FFFFFF;
					display: flex;
					justify-content: center;
					margin-bottom: 20rpx;
					.title_info{
						padding: 0 20rpx;
					}
				}
				.joiner_list{
					color: #FFFFFF;
					font-size: 30rpx;
					overflow: hidden;
					.scroll-Y {
						height: v-bind(rightHeight);
					}
					.new_joiner_name{
						padding: 10rpx 20rpx;
						display: flex;
						align-items: center;
						.name{
							margin-left: 10rpx;
							font-size: 24rpx;
						}
					}
				}
			}
		}
	}
</style>